package com.grademaster.controller;

import com.grademaster.common.R;
import com.grademaster.dto.ClassPageDto;
import com.grademaster.entity.Classes;
import com.grademaster.service.ClassesService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/classes")
@Api(tags = "班级相关接口")
@CrossOrigin(origins = {"http://localhost:8081"}, allowCredentials = "true")
public class ClassesController {

    @Autowired
    private ClassesService classesService;

    @ApiOperation("根据教师id查询班级列表")
    @GetMapping("/listByTeacher")
    public R listByTeacher(Long teacherId){
        return classesService.listByTeacher(teacherId);
    }
    @ApiOperation("获取所有班级信息")
    @GetMapping("/getAllClasses")
    public R getAllClasses() {
        return classesService.getAllClasses();
    }

    @ApiOperation("获取所有班级分页信息")
    @GetMapping("/getAllClassesByPage")
    public R getAllClassesByPage(ClassPageDto classPageDto) {
        return classesService.getAllClassesByPage(classPageDto);
    }
    @ApiOperation("导出成绩列表到Excel")
    @GetMapping("/exportExcel")
    public ResponseEntity exportExcel(ClassPageDto classPageDto){
        return classesService.exportExcel(classPageDto);
    }

    @ApiOperation("添加或修改班级")
    @PostMapping("/addOrEditClass")
    public R addOrEditClass(@RequestBody Classes classes) {
        return classesService.addOrEditClass(classes);
    }

    @ApiOperation("删除班级")
    @DeleteMapping("/deleteClass/{classId}")
    public R deleteMajor(@PathVariable("classId") String classId) {
        return classesService.deleteClass(classId);
    }

}
